package cn.zhz.dao;

import cn.zhz.pojo.Equipment;

import cn.zhz.pojo.EquipmentCondition;
import org.hibernate.Query;
import java.io.Serializable;
import java.util.List;

public class EquipmentDao extends BaseDao{
    public void save(Equipment eq){
        currentSession().save(eq);
    }
    public Equipment load(Serializable id){
        return (Equipment)currentSession().load(Equipment.class,id);
    }
    public void delete(Equipment equipment){
        currentSession().delete(equipment);
    }


    public List<Equipment> findByTypeId(Equipment condition){
        String hql = "from Equipment where typeId = :typeId";
        Query query = currentSession().createQuery(hql);
        query.setProperties(condition);
        return query.list();
    }

    public List<Equipment> findByPrice(Equipment condition){
        String hql = "from Equipment where priceFactory < :priceFactory";
        Query query = currentSession().createQuery(hql);
        query.setProperties(condition);
        return query.list();
    }
    public List<Equipment> findByDate(EquipmentCondition condition){
        String hql = "from Equipment where dateFactory > :dateStart and dateFactory < :dateEnd";
        Query query = currentSession().createQuery(hql);
        query.setProperties(condition);
        return query.list();
    }

    public List<Equipment> findEquipmentByCondition(String hql,EquipmentCondition condition){
        return currentSession().createQuery(hql).setProperties(condition).list();
    }
}
